﻿using System;
using ContractManagementSystem.BusinessLogic;
using ContractManagementSystem.Entity;
using System.Globalization;
namespace ContractManagementSystem.Controls
{
    public partial class AddLineManagerControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Submit.OnClientClick = "return ValidateLineManager();";
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            MessageLabel.Text = null;
            var lineManagerEntity = new LineManagerEntity
                                        {
                                            UserId = UserBusiness.InitialUser(FullNameTextBox.Text, "Client"),
                                            Birthday = DateTime.Parse(BirthDateTextBox.Text, CultureInfo.CurrentCulture),
                                            FullName = FullNameTextBox.Text,
                                            Gender = GenderDropDownList.SelectedIndex,
                                            Email = EmailTextBox.Text,
                                            PhoneNumber = PhoneNumberTextBox.Text,
                                            Title = TitleTextBox.Text
                                        };
            if(LineManagerBusiness.Insert(lineManagerEntity))
            {
                MessageLabel.Text = "Insert Success !";
                Response.Redirect("ViewAllLineManager.aspx");
            }
            else
            {
                MessageLabel.Text = "Insert False !";
            }
            MessageLabel.Text = LineManagerBusiness.Insert(lineManagerEntity) ? "Insert Success !" : "Insert False !";
        }
    }
}